/*
 * Copyright 2007 Jeffrey Palm
 */

import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;

public class UsernameForm extends Form implements CommandListener {
	
  private final Bloglines midlet;
  private final Displayable prev;	
  private final Command ok;
  private final TextField usernameField;
  private final TextField passwordField;
	
  public UsernameForm(Displayable prev, Bloglines midlet) {
    super("Set your user name");
    this.prev = prev;
    this.midlet = midlet;
    append("Set your user name");
    addCommand(ok = new Command("OK",Command.OK,1));
    setCommandListener(this);	
    usernameField = new TextField("Username:",Configuration.Get(Configuration.USERNAME_PARAM),50,TextField.ANY);
    passwordField = new TextField("Password:",Configuration.Get(Configuration.PASSWORD_PARAM),50,TextField.PASSWORD);
    append(usernameField);
    append(passwordField);
  }

  public void commandAction(Command c, Displayable arg1) {
    if (c == ok) {
      String username = usernameField.getString();
      String password = passwordField.getString();
      midlet.setUsername(username);
      midlet.setPassword(password);
      midlet.startShowing();
    } else {
      back();
    }
  }
	
  private void back() {
    if (prev != null) Display.getDisplay(midlet).setCurrent(prev);		
  }

}
